//
//  NYHomeView.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2017/12/4.
//  Copyright © 2017年 niuwaketang. All rights reserved.
//

#import "NYHomeView.h"
#import "NYHomeHeaderView.h"

//vc
#import "NYInstituteViewController.h"
#import "NYFocusViewController.h"
#import "NYSearchViewController.h"
#import "NYChoseBookViewController.h"
#import "NYAirlineViewController.h"

@interface NYHomeView () <NYHomeHeaderViewDelegate>

@end
@implementation NYHomeView

- (void)setupTableView {
    
    [super setupTableView];
    self.tableView.backgroundColor = UIColorMakeWithHex(@"#F3F4F5");

    [self setTableHeaderViewAction];
}
- (void)setTableHeaderViewAction {
    
    NYHomeHeaderView *view = [[NYHomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.width, (239.0 / 667.0 * __MAIN_SCREEN_HEIGHT__)) withDelegate:self];
    self.tableView.tableHeaderView = view;
    self.tableView.enableAutoAdjustHeader = YES;
}

//MARK NYHomeHeaderViewDelegate
- (void)clickOnTheButton:(NSInteger)index {
    
    switch (index) {
        case 1: {
            NYChoseBookViewController *viewController = [NYChoseBookViewController new];
            viewController.isShowBack = true;
            [self.controller.navigationController pushViewController:viewController animated:true];
            break;
        }
        case 2: {
            [self.controller.navigationController pushViewController:[NYInstituteViewController new] animated:true];
            break;
        }
        case 3: {
            [self.controller routeUrl:kNYMineURI param:nil];
            break;
        }
        case 4: {
            
            @weakify(self);
            [NYUserManager pushOrPresentLoginIfNeed:YES inViewController:nil completion:nil dismiss:^{
                
                @strongify(self);
                if (NYUserManager.isLogin) {
                    [self.controller.navigationController pushViewController:[NYAirlineViewController new] animated:true];
                }
            }];
            break;
        }

        default:
            break;
    }
}
- (void)didSelectCycleScrollViewItem:(NYHomeFocusModel *)focusModel {
    
    [self.controller.navigationController pushViewController:[[NYFocusViewController alloc] initWithFocusModel:focusModel] animated:true];
}
- (void)goToTheSearchViewController {
    
    [self.controller.navigationController pushViewController:[NYSearchViewController new] animated:true];
}

- (UIView *)configNavgationSearchView {
    UIView *searchView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH -  __WGWidth(159), 28.f)];
    [searchView setBackgroundColor:UIColorMakeWithHex(@"#FFFFFF")];
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:searchView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(14.f, 14.f)];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = searchView.bounds;
    maskLayer.lineCap = kCALineCapRound;
    maskLayer.lineJoin = kCALineJoinRound;
    maskLayer.path = path.CGPath;
    searchView.layer.mask = maskLayer;
    
    UILabel *keyLabel = [[UILabel alloc] initWithFrame:CGRectMake(19, 0, 100, 28.f)];
    keyLabel.font = UIFontMake(14);
    keyLabel.textColor = UIColorMakeWithHex(@"#D0D0D0");
    keyLabel.text = @"输入课程关键词";
    [searchView addSubview:keyLabel];
    
    UIImageView *searImgView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(searchView.frame) - 31, 6.5f, 15, 15)];
    searImgView.image = [UIImage sou_suo];
    [searchView addSubview:searImgView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goToTheSearchViewController)];
    tap.cancelsTouchesInView = false;
    [searchView addGestureRecognizer:tap];
    return searchView;
}

@end
